package com.itheima.pratice.test;

import java.util.ArrayList;
import java.util.stream.Stream;

public class StreamTest03 {
    //Stream流中间方法练习
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("张三丰");
        list.add("赵无极");
        list.add("敢为但");
        list.add("地位被");
        list.add("地位被");

        //limit(n) 获取前n个元素
        list.stream().limit(2).forEach(s -> System.out.println(s));
        System.out.println("==========");
        //skip(n) 跳过前n个元素
        list.stream().skip(2).forEach(s -> System.out.println(s));
        System.out.println("==========");
        //concat 合并两个流
        ArrayList<String> list1 = list;
        Stream.concat(list.stream(),list1.stream()).forEach(s -> System.out.println(s));
        System.out.println("==========");
        //distinct 去除重复
        list.stream().distinct().forEach(s -> System.out.println(s));
    }
}
